package com.AdvancedDemos.Learn网络编程.BS架构_网站服务器的基本原理;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;

public class ServerReaderThread extends Thread {
    private Socket socket;

    public ServerReaderThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        //  立即响应一个网页内容：“黑马程序员”给浏览器展示。
        try {
            OutputStream os = socket.getOutputStream();
            PrintStream ps = new PrintStream(os);
            ps.println("HTTP/1.1 200 OK");
            ps.println("Content-Type:text/html;charset=UTF-8");
            ps.println(); // 必须换行

            BufferedReader br = new BufferedReader(new FileReader("helloworld\\src\\com\\AdvancedDemos\\Learn网络编程\\BS架构_网站服务器的基本原理\\hello.html"));

            String line;
            while ((line = br.readLine()) != null) {
                ps.println(line);
            }

            br.close();
            ps.close();
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}